﻿
CREATE PROCEDURE [dbo].[P_OBTERLISTA_T11_USUARIO]
	@cd_usuario [int]
   ,@ds_login [varchar](50)
   ,@nm_usuario [varchar](50)
   ,@tx_senha [text]
   ,@cd_setor [int]
   ,@cd_predio [int]
   
AS
BEGIN
	SELECT
	T.cd_usuario
    ,T.ds_login
    ,T.nm_usuario
    ,T.tx_senha
    ,T.cd_setor
    ,T.cd_predio
    ,t08.ds_identificacao ds_identificacao_predio
    ,t09.ds_setor
  FROM T11_USUARIO t
  inner join T08_PREDIO t08 on t08.cd_predio = t.cd_predio
  inner join T09_SETOR t09 on t09.cd_setor = t.cd_setor
  WHERE
    (t.cd_usuario = @cd_usuario OR @cd_usuario IS NULL)
    AND (t.ds_login = @ds_login OR @ds_login IS NULL)
    AND (t.nm_usuario like '%' + @nm_usuario + '%' OR @nm_usuario IS NULL)
    AND (t.cd_setor = @cd_setor OR @cd_setor IS NULL)
    AND (t.cd_predio = @cd_predio OR @cd_predio IS NULL)
    
END